package com.study.cloud.gateway.core.netty;

import com.study.cloud.gateway.core.context.HttpRequestWrapper;
import com.study.cloud.gateway.core.netty.process.NettyProcessor;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundHandlerAdapter;
import io.netty.channel.SimpleChannelInboundHandler;
import io.netty.handler.codec.http.FullHttpRequest;

/**
 * @author wangwancheng
 * @create 2025/7/18 23:00
 */
public class NettyHttpServerHandler extends ChannelInboundHandlerAdapter {

    private final NettyProcessor nettyProcessor;

    public NettyHttpServerHandler(NettyProcessor nettyProcessor) {
        this.nettyProcessor = nettyProcessor;
    }

    @Override
    public void channelRead(ChannelHandlerContext channelHandlerContext, Object o) throws Exception {
        FullHttpRequest fullHttpRequest = (FullHttpRequest) o;
        HttpRequestWrapper httpRequestWrapper = new HttpRequestWrapper(fullHttpRequest, channelHandlerContext);
        nettyProcessor.process(httpRequestWrapper);

    }
}
